<script>
import { getVideoClass, getClass } from "../assets/api/info.js";
import { onMounted, reactive, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";

export default {
  components: {},
  setup() {
    let route = useRoute();
    // console.log(route.query);
    let router = useRouter();
    const list = reactive({
      // 热门视频
      videoList: [],
      // 横向视频
      videoLists: [],
      id: route.query.id,
      name: route.query.name,
      // 加载
      load:true
    });
    function filters(id) {
      let w = id > 10000 ? (id / 10000).toFixed(1) + "万" : id;
      return w;
    }
    function toHHmmss(data) {
      var time;
      var hours = parseInt((data % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      var minutes = parseInt((data % (1000 * 60 * 60)) / (1000 * 60));
      var seconds = parseInt((data % (1000 * 60)) / 1000);
      time =
        (hours < 10 ? "0" + hours : hours) +
        ":" +
        (minutes < 10 ? "0" + minutes : minutes) +
        ":" +
        (seconds < 10 ? "0" + seconds : seconds);
      return time;
    }
    //视频跳转传值
    let details_article = (data,index) => {
      window.localStorage.setItem("article_video", JSON.stringify(data));
      let id = index + 1;
      router.push({
        path: "/detailsvideo",
        query: {
          id,
        },
      });
    };
    
    onMounted(() => {
      //视频
      getVideoClass({
        category_id: list.id,
      }).then((data) => {
        console.log(data.data);
        list.videoList = data.data;
        // console.log(list.videoList);
      });
      getClass({
        category_id: list.id,
        pagesize: "20",
        search_type: 1,
      }).then((data) => {
        list.videoLists = data.data.list.slice(0,8);
        list.load = false
      });
    });
    return {
      ...toRefs(list),
      toHHmmss,
      filters,
      details_article,
    };
  },
};
</script>
<template>
  <div class="container">
    <van-sticky>
      <div class="nav">
        <div class="nav-in">
          <div class="nav-back">
            <a href="javascript:;" @click="$router.go(-1)">
              <i class="iconfont icon-zuobian"></i>
            </a>
          </div>
          <div class="nav-title">{{ name }}</div>
        </div>
      </div>
    </van-sticky>
      <van-loading v-if="load" size="30">加载中...</van-loading>
    
    <div class="hot" v-if="videoList.length != 0">
      <div class="hot-title">
        <i class="iconfont icon-icon1"></i>
        <span>本区热门</span>
      </div>

      <ul class="hotlist">
        <li
          v-for="(item, index) in videoList"
          :key="item.id"
          @click="details_article(item,index)"
        >
          <div class="img">
            <img :src="item.video_icon" alt="" />
            <div class="text">
              <div class="num">
                <i class="iconfont icon-paishipin"></i>
                <span>{{ filters(item.video_time) }}</span>
              </div>
              <div class="time">
                <span>{{ item.video_format_time }}</span>
              </div>
            </div>
          </div>
          <div class="bottom">
            <div class="title one-txt-cut">{{ item.title }}</div>
            <div class="label">{{ name }}</div>
          </div>
        </li>
      </ul>
    </div>

    <div class="video">
      <div class="video-title">
        <i class="iconfont icon-shijian"></i>
        <span>最近更新</span>
      </div>
      <ul class="video-list">
        <li
          v-for="(item, index) in videoLists"
          :key="item.id"
          @click="details_article(item,index)"
        >
          <div class="img">
            <img :src="item.video_icon" />
            <div class="text-list">
              <div class="time">{{ toHHmmss(item.video_time) }}</div>
            </div>
          </div>
          <div class="text">
            <div class="name">{{ item.title }}</div>
            <div class="acthor">up主: {{ item.nickname }}</div>
            <div class="icon">
              <div class="bf">
                <i class="icon-paishipin iconfont"></i>
                <div class="num">{{ item.review_num }}</div>
              </div>
              <div class="pl">
                <i class="icon-comment_light iconfont"></i>
                <div class="num">{{ item.thumb_up }}</div>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<style lang="scss" scoped>
// 最近更新
.video {
  padding: 0 14px 2px;
  .video-list {
    .img {
      position: relative;
      border-radius: 8px;
      overflow: hidden;
      .text-list {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 36px;
        background: linear-gradient(-180deg, rgba(0, 0, 0, 0) 0%, #000000 97%);
        z-index: 1;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 8px 0;
        line-height: 36px;
        flex-direction: row-reverse;
        .time {
          height: 17px;
          line-height: 17px;
          font-size: 10px;
          text-align: right;
          color: #fff;
        }
      }
    }
    li {
      margin-bottom: 16px;
      display: flex;
      img {
        width: 128px;
        height: 74px;
        border-radius: 8px;
      }
      .text {
        margin-left: 10px;
        .name {
          width: 215px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          color: #1b1b1b;
          font-weight: bold;
          font-size: 14px;
          margin-bottom: 6px;
        }
        .acthor {
          font-size: 12px;
          color: #ababab;
          margin-bottom: 14px;
        }
        .icon {
          display: flex;
          font-size: 12px;
          color: #c4c4c4;
          .iconfont {
            margin-right: 4px;
          }
          .bf {
            display: flex;
            margin-right: 16px;
            align-items: center;
          }
          .pl {
            display: flex;
            align-items: center;
          }
        }
      }
    }
  }
}
.video-title {
  height: 40px;
  line-height: 40px;
  font-weight: 700;
  color: #414141;
  display: flex;
  span {
    font-size: 14px;
  }
  .icon-shijian {
    color: red;
    margin-right: 5px;
  }
}
// 视频
.hot {
  padding: 0px 10px 0;
  .hot-title {
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    color: #242629;
    font-weight: 700;
    display: flex;
    .icon-zuobian {
      font-weight: 700;
    }
    .icon-icon1 {
      color: red;
      font-size: 20px;
      margin-right: 5px;
    }
  }
  h3 {
    font-size: 16px;
    font-weight: 600;
    font-family: 黑体;
    margin: 10px 0 10px;
  }
  ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    li {
      width: 49%;
      background-color: #fff;
      margin-bottom: 10px;
      border-radius: 8px;
      .img {
        position: relative;
        // width: 100%;

        img {
          width: 100%;
          height: 98px;
          border-radius: 8px;
        }
        .text {
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          height: 36px;
          background: linear-gradient(
            -180deg,
            rgba(0, 0, 0, 0) 0%,
            #000000 97%
          );
          z-index: 1;
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 16px 8px 0;
          line-height: 36px;
          .num {
            height: 17px;
            line-height: 17px;
            font-size: 10px;
            text-align: right;
            display: flex;
            align-items: center;
            .iconfont {
              color: #fff;
              font-size: 10px;
              margin-right: 4px;
            }
            span {
              font-size: 10px;
              color: #fff;
            }
          }
          .time {
            height: 17px;
            line-height: 17px;
            font-size: 10px;
            text-align: right;
            color: #fff;
          }
        }
      }
      .bottom {
        height: 40px;
        display: flex;
        align-items: center;
        .title {
          flex: 1;
          color: #1e1e1e;
          font-size: 13px;
          transform: scale(0.85, 0.85);
        }
        .label {
          color: #fe1f73;
          font-size: 14px;
          transform: scale(0.83, 0.83);
          width: 40px;
          height: 24px;
          line-height: 24px;
          border-radius: 6px 3px 5px 6px;
          background-color: #ffd3df;
          text-align: center;
          margin-right: 8px;
        }
      }
    }
  }
}
// 头部
.nav {
  width: 100%;
  padding: 0 16px;
  -webkit-transform: translateZ(1px);
  background: linear-gradient(270deg, #7b0b3b 0%, #d51c78 100%);

  font-size: 14.5px;
  font-weight: 500;
  color: #fff;
  transform: translateZ(1px);
}
.nav-in {
  height: 45px;
  line-height: 45px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  justify-content: flex-start;
  .iconfont {
    color: #fff;
  }
  .nav-title {
    font-size: 18px;
    font-weight: 700;
    margin-left: 10px;
  }
}
::v-deep .van-share-sheet__options {
  justify-content: space-around;
  padding: 16px 0;
}
::v-deep .van-loading {
  position: fixed;
  top: 100px;
  z-index: 100;
  width: 100%;
  height: 400px;
  line-height: 400px;
  text-align: center;
}
</style>
